﻿using System.Collections.Generic;

namespace Microsoft.Xna.Framework.Graphics
{
	/// <summary>
	/// Manipulates a collection of EffectPass objects.
	/// </summary>
	public sealed class EffectPassCollection : IEnumerable<EffectPass>
	{
		private List<EffectPass> pPass;

		#region Properties
		/// <summary>
		/// Gets the number of objects in the collection.
		/// </summary>
		public int Count
		{
			get { return pPass.Count; }
		}

		/// <summary>
		/// Gets a specific element in the collection by using an index value.
		/// </summary>
		/// <param name="index">Index of the EffectPass to get.</param>
		public EffectPass this[int index]
		{
			get
			{
				if ((index >= 0) && (index < this.pPass.Count))
				{
					return this.pPass[index];
				}
				return null;
			}
		}

		/// <summary>
		/// Gets a specific element in the collection by using a name.
		/// </summary>
		/// <param name="name">Name of the EffectPass to get.</param>
		public EffectPass this[string name]
		{
			get
			{
				List<EffectPass>.Enumerator enumerator = this.pPass.GetEnumerator();
				if (enumerator.MoveNext())
				{
					do
					{
						EffectPass current = enumerator.Current;
						if (current._name == name)
						{
							return current;
						}
					}
					while (enumerator.MoveNext());
				}
				return null;
			}
		}
		#endregion

		#region Constructor
		internal EffectPassCollection(EffectTechnique technique, int count)
		{
			this.pPass = new List<EffectPass>(count);
		}
		#endregion

		#region Private Methods
		IEnumerator<EffectPass> IEnumerable<EffectPass>.GetEnumerator()
		{
			return pPass.GetEnumerator();
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return pPass.GetEnumerator();
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Gets an enumerator that can iterate through the EffectPassCollection.
		/// </summary>
		public List<EffectPass>.Enumerator GetEnumerator()
		{
			return pPass.GetEnumerator();
		}
		#endregion
	}
}
